package ooday04;

import java.util.concurrent.Callable;

public class Test {
    public static void main(String[] args) {

        //Animal是抽象类不可实例化， Animal 0 = new Animal();
        Animal[] animals = new Animal[5];//创建Animal数组对象
        animals[0] = new Dog("小黑狗",2,"黑");
        animals[1] = new Dog("小白狗",1,"白");
        animals[2] = new Fish("小黑鱼",2,"黑");
        animals[3] = new Fish("小金鱼",3,"金");
        animals[4] = new Chick("小花鸡",4,"花");
        for (int i = 0; i <animals.length ; i++) {
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();

            if(animals[i] instanceof  Dog){
                Dog dog = (Dog) animals[i];
                dog.lookHome(); //黑狗 白狗看门 游泳
                dog.swim();
            }
            if(animals[i] instanceof Fish){
                Fish fish = (Fish) animals[i];
                fish.swim();//黑鱼 金鱼游泳
            }
            if (animals[i] instanceof Chick){
                Chick chick = (Chick) animals[i];
                chick.layEggs();//花鸡下蛋
            }
    }




/*        Dog[] dog = new Dog[3];
        dog[0] = new Dog("小黄狗",1,"黄");
        dog[1] = new Dog("小白狗",2,"白");
        dog[2] = new Dog("小灰狗",3,"灰");
        System.out.println(dog[2].name);
        dog[0].age = 3;
        System.out.println(dog[0].age);
        for (int i = 0; i <dog.length ; i++) {
            dog[i].eat();
        }

        Chick[] chicks = new Chick[2];
        chicks[0] = new Chick("小黄鸡",3,"黄");
        chicks[1] = new Chick("小红鸡",3,"红");
        for(int i=0;i<chicks.length;i++){
            System.out.println(chicks[i].name);
            chicks[i].eat();
        }

        Fish[] fish = new Fish[3];
        fish[0] = new Fish("小灰鱼",2,"灰");
        fish[1] = new Fish("小白鱼",4,"白");
        fish[2] = new Fish("小蓝鱼",1,"蓝");
        for(int i=0;i<fish.length;i++){
            System.out.println(fish[i].name);
            fish[i].eat();
        }*/
    }
}
